<?php

namespace Tasks;

use Doctrine\Common\Cli\Tasks\AbstractTask,
    Doctrine\Common\Cli\CliException;

class HelpTask extends AbstractTask
{

    public function buildDocumentation()
    {
        $doc = $this->getDocumentation();
        $doc->setName('help')
            ->setDescription('Exposes helpful information about all available tasks.');
    }

    public function run() 
    {
        $this->getPrinter()->writeln('Available Tasks:', 'HEADER')->write(PHP_EOL);

        // Find the CLI Controller
        $cliController = $this->getNamespace()->getParentNamespace();
        
        // Switch between ALL available tasks and display the basic Help of each one
        $availableTasks = $cliController->getAvailableTasks();
        //unset($availableTasks['Core:Help']);
        
        ksort($availableTasks);
        
        foreach (array_keys($availableTasks) as $taskName) {
            $cliController->runTask($taskName, array('basic-help' => true));
        }
    }

    public function extendedHelp()
    {
        $this->run();
    }
}